{% extends 'dashboard/base.html' %}

{% block body %}

{#    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>#}
    <script type="text/javascript">

        $("#checkAll").change(function () {
            $("input:checkbox").prop('checked', $(this).prop("checked"));
        });
        $(document).ready(function () {
            $('.btn-danger').click(function(){
            if (confirm('Are you sure you want to delete this?')) {
                var scan_id = ['a7af5b68-b661-45ad-90fd-ffa27526cdce'];
                $.each($("input[name='del_vuln_id']:checked"), function () {
                    scan_id.push($(this).val());
                });

                var json_scanid = scan_id.join(", ");
                $.ajax({
                    type: 'POST',
                    <!--contentType: 'application/json; charset=utf-8',-->
                    url: '{% url 'networkscanners:del_vuln' %}',
                    data: {
                        del_vuln: json_scanid,
                        scan_id: $('input[name=scan_id]').val(),
                        csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
                    },
                    sucess: function () {
                    }
                });
                setTimeout(function () {
                    location.reload();
                }, 1000);
            }
            });

        });

$(document).on('click', '.confirm-delete', function(){
    return confirm('Are you sure you want to delete this?');
})
    </script>


            <div class="row">
                <div class="col-md-12">
                    <div class="card">
                        <div class="card-body">
                            <div class="float-right">
                                <button type="button" class="btn btn-danger btn-mini" onclick="">Delete Selected
                                </button>
                            </div>
                            <br>
                            <div class="d-md-flex align-items-center">
                                <h1 class="card-title">Vulnerability List</h1>
                            </div>
                            <br>
                            <div class="row">
                                <div class="table-responsive">
                                    <table id="data_table" class="table table-bordered data-table">
                                        <thead>
                                        <tr>
                                            <th>
                                                <label class="customcheckbox m-b-20">
                                                    <input type="checkbox" id="mainCheckbox">
                                                    <span class="checkmark"></span>
                                                </label>
                                            </th>
                                            <th>Vulnerability</th>
                                            <th>Severity</th>
                                            <th>Host</th>
                                            <th>Location</th>
                                            <th>JIRA Ticket</th>
                                            <th>False Positive</th>
                                            <th>Status</th>
                                            <th>Delete</th>
                                            <!--<th></th>-->
                                            <th>Mark</th>
                                        </tr>
                                        </thead>
                                        <tfoot>

                                        </tfoot>
                                        <tbody>{% for data in all_vuln %}
                                            <tr data-target="#">
                                                <td>
                                                    <form>
                                                        <label class="customcheckbox">
                                                            <input type="checkbox" class="listCheckbox"
                                                                   value="{{ data.vul_id }}"
                                                                   name="del_vuln_id"
                                                                   onClick="reload">
                                                            <span class="checkmark"></span>
                                                        </label>
                                                    </form>
                                                </td>
                                                <td>
                                                    <a href="{% url 'networkscanners:vuln_check' %}?vuln_id={{ data.vul_id }}">{{ data.name }}</a>
                                                </td>
                                                <td><span
                                                        class="badge badge-pill badge-{{ data.vuln_color }}">{{ data.threat }}</span>
                                                </td>

                                                <td>{{ data.host }}</td>
                                                <td>{{ data.port }}</td>
                                                <td><a href="{{ jira_url }}browse/{{ data.jira_ticket }}"
                                                       target="_blank">{{ data.jira_ticket }}</a>
                                                </td>
                                                {% if data.false_positive == 'No' %}
                                                <td>
                                                    <form method="POST" action="{% url 'networkscanners:vul_details' %}">{% csrf_token %}
                                                        <input type="hidden" name="vuln_id" value="{{ data.vul_id }}">
                                                        <input type="hidden" name="scan_id" value="{{ scan_id }}">
                                                        <input type="hidden" name="false" value="Yes">
                                                        <input type="hidden" name="status" value="Closed">
                                                        <button class="btn btn-outline-info btn-mini">Yes</button>
                                                    </form>
                                                </td>
                                                {% endif %}
                                                {% if data.false_positive == 'Yes' %}
                                                    <td>
                                                    <form method="POST" action="{% url 'networkscanners:vul_details' %}">{% csrf_token %}
                                                        <input type="hidden" name="vuln_id" value="{{ data.vul_id }}">
                                                        <input type="hidden" name="scan_id" value="{{ scan_id }}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Open">
                                                        <button class="btn btn-info btn-mini">No</button>
                                                    </form>
                                                </td>
                                                {% endif %}
                                                <td>
                                                    {{ data.vuln_status }}
                                                </td>
                                                <td class="confirm-delete">
                                                    <div>
                                                        <form action="{% url 'networkscanners:del_vuln' %}"
                                                              method="POST"
                                                              class="form-horizontal">
                                                            {% csrf_token %}
                                                            <input type="hidden" name="del_vuln"
                                                                   value="{{ data.vul_id }}">
                                                            <input type="hidden" name="scan_id" value="{{ scan_id }}">
                                                            <button class="btn btn-warning"><i class="fas fa-trash"></i>
                                                            </button>
                                                        </form>
                                                    </div>
                                                </td>
                                            {% if data.vuln_status == 'Open' %}
                                                <td>
                                                    <form method="POST"
                                                          action="{% url 'networkscanners:vul_details' %}">{% csrf_token %}
                                                        <input type="hidden" name="vuln_id" value="{{ data.vul_id }}">
                                                        <input type="hidden" name="scan_id" value="{{ scan_id }}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Closed">
                                                        <button class="btn btn-outline-info btn-mini">Close</button>
                                                    </form>
                                                </td>
                                            {% endif %}
                                            {% if data.vuln_status == 'Closed' %}
                                                <td>
                                                    <form method="POST"
                                                          action="{% url 'networkscanners:vul_details' %}">{% csrf_token %}
                                                        <input type="hidden" name="vuln_id" value="{{ data.vul_id }}">
                                                        <input type="hidden" name="scan_id" value="{{ scan_id }}">
                                                        <input type="hidden" name="false" value="No">
                                                        <input type="hidden" name="status" value="Open">
                                                        <button class="btn btn-info btn-mini">Open</button>
                                                    </form>
                                                </td>
                                            {% endif %}
                                            </tr>
                                        {% endfor %}
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



{% endblock %}
